//
//  WKNavigationView.m
//  ourToken
//
//  Created by wakeup on 2018/5/30.
//  Copyright © 2018年 ourtoken. All rights reserved.
//

#import "WKNavigationView.h"
#import "WKBaseHeader.h"

@interface WKNavigationView ()

@end

@implementation WKNavigationView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        
        _buttonSpace = 15;
        _buttonWidth = 80;
        _topTitleViewHeight = 44;
        
        self.backgroundColor = [UIColor whiteColor];
        //不包含状态栏视图
        [self addSubview:self.topTitleView];
        //左侧按钮
        [self.topTitleView addSubview:self.topLeftButton];
        //右侧按钮
        [self.topTitleView addSubview:self.topRightButton];
        //中间标题
        [self.topTitleView addSubview:self.topTitleLabel];
        //底部灰色的线
        [self addSubview:self.topLineView];
    }
    return self;
}

//不包含状态栏视图
- (UIView *)topTitleView {
    if (_topTitleView == nil) {
        _topTitleView = [[UIView alloc] initWithFrame:CGRectMake(0, self.frame.size.height-_topTitleViewHeight, AppManager.width, _topTitleViewHeight)];
        _topTitleView.backgroundColor = [UIColor clearColor];
    }
    return _topTitleView;
}

//左侧按钮
- (UIButton *)topLeftButton {
    if (_topLeftButton == nil) {
        _topLeftButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _topLeftButton.frame = CGRectMake(_buttonSpace, 0, _buttonWidth, _topTitleViewHeight);
        [_topLeftButton addTarget:self action:@selector(leftTopButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        _topLeftButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    }
    return _topLeftButton;
}

//右侧按钮
- (UIButton *)topRightButton {
    if (_topRightButton == nil) {
        _topRightButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _topRightButton.frame = CGRectMake(AppManager.width-_buttonWidth-_buttonSpace, 0, _buttonWidth, _topTitleViewHeight);
        _topRightButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
        _topRightButton.titleLabel.font = [UIFont systemFontOfSize:15];
        [_topRightButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [_topRightButton addTarget:self action:@selector(rightTopButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _topRightButton;
}

//中间标题
- (UILabel *)topTitleLabel {
    if (_topTitleLabel == nil) {
        _topTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(_buttonSpace+_buttonWidth+5, 0, AppManager.width-(_buttonSpace+_buttonWidth+5)*2, _topTitleViewHeight)];
        _topTitleLabel.font = [UIFont systemFontOfSize:18];
//        _topTitleLabel.font = [UIFont boldSystemFontOfSize:20];
        _topTitleLabel.textAlignment = NSTextAlignmentCenter;
        _topTitleLabel.numberOfLines = 0;
    }
    return _topTitleLabel;
}

//底部灰色的线
- (UIView *)topLineView {
    if (_topLineView == nil) {
        _topLineView = [[UIView alloc] initWithFrame:CGRectMake(0, self.frame.size.height-0.5, AppManager.width, 0.5)];
        _topLineView.backgroundColor = [UIColor grayColor];
    }
    return _topLineView;
}

//左侧按钮点击
- (void)leftTopButtonClick:(UIButton *)sender {
    if (self.delegate && [self.delegate respondsToSelector:@selector(leftButtonClick:)]) {
        [self.delegate leftButtonClick:sender];
    }
}

//右侧按钮点击
- (void)rightTopButtonClick:(UIButton *)sender {
    if (self.delegate && [self.delegate respondsToSelector:@selector(rightButtonClick:)]) {
        [self.delegate rightButtonClick:sender];
    }
}

@end
